package com.example.wly.application_3_homework;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.example.background.R;

public class colorActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_color);
        Button btnGreen = (Button) findViewById(R.id.btn_green);
        Button btnRen = (Button) findViewById(R.id.btn_red);
        Button btnOrange = (Button) findViewById(R.id.btn_orange);
        Button btnMediumSpringGreen = (Button) findViewById(R.id.btn_MediumSpringGreen);
        Button btnMediumVioletRed = (Button) findViewById(R.id.btn_MediumVioletRed);
        Button btnPink = (Button) findViewById(R.id.btn_pink1);
        //给控件添加监听
        btnGreen.setOnClickListener(this);
        btnRen.setOnClickListener(this);
        btnOrange.setOnClickListener(this);
        btnMediumSpringGreen.setOnClickListener(this);
        btnMediumVioletRed.setOnClickListener(this);
        btnPink.setOnClickListener(this);
    }
        public void onClick(View v) {
            //点击按钮返回主界面
            //finish 结束 返回主界面
            //将背景颜色值带回主界面
            //1-数据
            //发生点击事件的控件就是参数V
            ColorDrawable colorDrawable = (ColorDrawable) v.getBackground();
            int colorValue = colorDrawable.getColor();
            //2-数据---》intent
            Intent intent = new Intent();
            intent.putExtra("color", colorValue);
            //3-intent--》result中带回数据
            setResult(2, intent);//结果码是2
            //4-finish结束Activity
            finish();
    }


}
